home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / rigctrl / catcntrl / catcom2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-31  |  51.3 KB  |  2,524 lines

  1. /*12/05/95 E. L. L.*/
  2. /*YAESU FT-767GX CAT (Computer Aided Tuning or Transceive) PROGRAM*/
  3. /*Setup to use serial port com1 and operate on a 486 machine*/
  4.  
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <bios.h>
  8. #include <graph.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <process.h>
  13. #define ESC 27
  14. #define clrscr() system("cls")
  15. #define CLRSCR printf("%c[2J",ESC)
  16. #define FALSE 0
  17. #define TRUE 1
  18. #define CLREOL printf("%c[K",ESC)
  19. #define EDTB "\0"
  20. #define BACKSPACE printf("\010")
  21. #define PAD 2
  22. #define FACTOR 800
  23. #define TIMEOUT 18000
  24. #define MAXGENERAL 100
  25. #define MAXREPEATER 25
  26.  
  27. void examine_files(int num);
  28. void disk_memory_control(void);
  29. int selection(int choice);
  30. int add_station(int num);
  31. int delete_station(int num);
  32. int getreply(void);
  33. void backup(int spaces);
  34. int gen_insert(int rcnt , int num);
  35. int loadfile(int num);
  36. int rep_insert(int rcnt , int num);
  37. int savedata(int maxcnt, int num);
  38. void input_data(int num);
  39. void remove_record(int del , int cnt , int num);
  40. void reindex(int cnt , int num , int j);
  41. void viewfile(int cnt , int num);
  42. void press_enter(int x, int y);
  43. char *convert(char *buff , char *freq);
  44. void recall(int num);
  45. void do_it(char *func);
  46. void store(int num);
  47. char *hertz(char *buffer, int k);
  48. void vfo_mode(int m);
  49. void get_data(int num);
  50. void pl_tone(int b);
  51. void edit_control(void);
  52. char edit_selection(char opt);
  53. void edit_records(int num);
  54. void edit_station_record(int rec, int num);
  55.  
  56. struct general
  57. {
  58.     char rec[3 + PAD];
  59.     char freq[8 + PAD];
  60.     char mode[3 + PAD];
  61.     char call[8 + PAD];
  62.     char loc[34 + PAD];
  63. };
  64. struct general g[MAXGENERAL];
  65. struct general gentemp,*ptg1,*ptg2;
  66.  
  67. struct repeater
  68. {
  69.     char rec[3 + PAD];
  70.     char afreq[8 + PAD];
  71.     char bfreq[8 + PAD];
  72.     char mode[3 + PAD];
  73.     char tone[6 +  PAD];
  74.     char call[8 + PAD];
  75.     char loc[34 + PAD];
  76. };
  77. struct repeater r[MAXREPEATER];
  78. struct repeater reptemp,*ptr1,*ptr2;
  79.  
  80. char cmd[10],modifier[15],binary[8];
  81. char *lstr[] = { "67.0","71.9","77.0","82.5","88.5","94.8","100.0","103.5",
  82.          "107.2","110.9","114.8","118.8","123.0","127.3","131.8",
  83.          "136.5","141.3","146.2","151.4","156.7","162.2","167.9",
  84.          "173.8","179.9","186.2","192.8","203.5","210.7","218.1",
  85.          "225.7","233.6","241.8","250.3",EDTB };
  86.  
  87. char *hstr[] = { "67.0","71.9","74.7","77.0","79.7","82.5","85.4","88.5",
  88.          "91.5",EDTB };
  89.  
  90. char **ptr;
  91. int status[90],bytcnt,clear;
  92. int catflag,endprog;
  93. int xmiterror;
  94.  
  95. parse(chptr)
  96. char *chptr;
  97. {
  98. char *mod;
  99. int k;
  100. for(k=0;k<=15;k++)
  101.     modifier[k] = 0;
  102. mod = modifier;
  103. k = 0;
  104. while((*chptr != 0) && (*chptr != ' '))
  105.     {
  106.     *chptr++;
  107.     k++;
  108.     }
  109. if(*chptr == ' ')
  110.     {
  111.     *chptr++;
  112.     while(*chptr != 0)
  113.     *mod++ = *chptr++;
  114.     }
  115.     return(k);
  116. }       /*end of parse*/
  117.  
  118. void match(func,cnt)
  119. char *func;
  120. int cnt;
  121. {
  122. char *up,*dn,*cat,*band,*split,*clar,*mtov,*vtom,*swap,*prog;
  123. char *freq,*vfo,*mem,*mode,*ham,*tone,*check,*aclr,*quit;
  124. char *on,*off,*gen,*a,*b,*mr,*lsb,*usb,*cw,*am,*fm,*fsk;
  125. char *hiq,*loq,*m0,*m1,*m2,*m3,*m4,*m5,*m6,*m7,*m8,*m9;
  126. char *help;
  127.  
  128. up = "up"; dn= "dn"; cat= "cat"; off = "off"; on = "on"; band = "band";
  129. split = "split"; clar = "clar"; mtov = "mtov"; vtom = "vtom"; swap = "swap";
  130. prog = "prog";hiq = "hiq";loq = "loq"; freq = "freq";
  131. vfo = "vfo"; a = "a"; b = "b"; mr = "mr"; mem = "mem"; m0 = "0";
  132. m1 = "1"; m2 = "2"; m3 = "3"; m4 = "4"; m5 = "5"; m6 = "6"; m7 = "7";
  133. m8 = "8"; m9 = "9"; mode = "mode"; lsb = "lsb"; usb = "usb"; cw = "cw";
  134. am = "am"; fm = "fm"; fsk = "fsk"; ham = "ham"; gen = "gen";
  135. tone = "tone"; check = "check"; aclr = "aclr"; quit = "quit"; help = "help";
  136.  
  137. if((strncmp(func,up,cnt) == 0) && (cnt == 2))
  138.     {
  139.     bytcnt = 5;
  140.     cmd[4] = 0x2;
  141.     return;
  142.     }
  143. else
  144. if((strncmp(func,dn,cnt) == 0) && (cnt == 2))
  145.     {
  146.     bytcnt = 5;
  147.     cmd[4] = 0x3;
  148.     return; 
  149.     }
  150. else
  151. if((strncmp(func,cat,cnt) == 0) && (cnt == 3))
  152.     {
  153.     bytcnt = 86;
  154.     cmd[4] = 0x0;
  155.     if(strcmp(modifier,on) == 0)
  156.         {
  157.         cmd[3] = 0x0;
  158.         catflag = TRUE;
  159.         }
  160.     else
  161.     if(strcmp(modifier,off) == 0)
  162.         {
  163.         cmd[3] = 0x1;
  164.         catflag = FALSE;
  165.         }
  166.     else
  167.         {
  168.         errmsg();
  169.         return;
  170.         }
  171.     return;
  172.     }
  173. else
  174. if((strncmp(func,band,cnt) == 0) && (cnt == 4))
  175.     {
  176.     bytcnt = 5;
  177.     if(strcmp(modifier,up) == 0)
  178.         cmd[4] = 0x6;
  179.     else
  180.     if(strcmp(modifier,dn) == 0)
  181.         cmd[4] = 0x7;
  182.     else
  183.         {
  184.         errmsg();
  185.         return;
  186.         }
  187.     return;
  188.     }
  189. else
  190. if((strncmp(func,split,cnt) == 0) && (cnt == 5))
  191.     {
  192.     bytcnt = 26;
  193.     cmd[4] = 0xA;
  194.     cmd[3] = 0x30;
  195.     return;
  196.     }
  197. else
  198. if((strncmp(func,clar,cnt) == 0) && (cnt == 4))
  199.     {
  200.     bytcnt = 26;
  201.     cmd[4] = 0xA;
  202.     cmd[3] = 0x40;
  203.     return;
  204.     }
  205. else
  206. if((strncmp(func,mtov,cnt) == 0) && (cnt == 4))
  207.     {
  208.     bytcnt = 26;
  209.     cmd[4] = 0xA;
  210.     cmd[3] = 0x50;
  211.     return;
  212.     }
  213. else
  214. if((strncmp(func,vtom,cnt) == 0) && (cnt == 4))
  215.     {
  216.     bytcnt = 86;
  217.     cmd[4] = 0xA;
  218.     cmd[3] = 0x60;
  219.     return;
  220.     }
  221. else
  222. if((strncmp(func,swap,cnt) == 0) && (cnt == 4))
  223.     {
  224.     bytcnt = 86;
  225.     cmd[4] = 0xA;
  226.     cmd[3] = 0x70;
  227.     return;
  228.     }
  229. else
  230. if((strncmp(func,prog,cnt) == 0) && (cnt == 4))
  231.     {
  232.     bytcnt = 5;
  233.     for(cnt=0;cnt<=15;cnt++)
  234.         func[cnt] = modifier[cnt];
  235.     cnt = parse(func);
  236.     if((strncmp(func,up,cnt) == 0) && (cnt == 2))
  237.         {
  238.         getnumber();
  239.         cmd[4] = 0x4;
  240.         cmd[3] = cmd[1];
  241.         cmd[2] = cmd[0];
  242.         }
  243.     else
  244.     if((strncmp(func,dn,cnt) == 0) && (cnt == 2))
  245.         {
  246.         getnumber();
  247.         cmd[4] = 0x5;
  248.         cmd[3] = cmd[1];
  249.         cmd[2] = cmd[0];
  250.         }
  251.     else
  252.         {
  253.         errmsg();
  254.         return;
  255.         }
  256.     return;
  257.     }
  258. else
  259. if((strncmp(func,freq,cnt) == 0) && (cnt == 4))
  260.     {
  261.     bytcnt = 5;
  262.     getnumber();
  263.     cmd[4] = 0x8;
  264.     return;
  265.     }
  266. else
  267. if((strncmp(func,vfo,cnt) == 0) && (cnt == 3))
  268.     {
  269.         bytcnt = 5;
  270.         cmd[4] = 0x9;
  271.     if(strcmp(modifier,a) == 0)
  272.         cmd[3] = 0x0;
  273.     else
  274.     if(strcmp(modifier,b) == 0)
  275.         cmd[3] = 0x1;
  276.     else
  277.     if(strcmp(modifier,mr) == 0)
  278.         cmd[3] = 0x2;
  279.     else
  280.         {
  281.         errmsg();
  282.         return;
  283.         }
  284.     return;
  285.     }
  286. else
  287. if((strncmp(func,mem,cnt) == 0) && (cnt == 3))
  288.     {
  289.         bytcnt = 8;
  290.         cmd[4] = 0xA;
  291.     if(strcmp(modifier,m0) == 0)
  292.         cmd[3] = 0x0;
  293.     else
  294.     if(strcmp(modifier,m1) == 0)
  295.         cmd[3] = 0x1;
  296.     else
  297.     if(strcmp(modifier,m2) == 0)
  298.         cmd[3] = 0x2;
  299.     else
  300.     if(strcmp(modifier,m3) == 0)
  301.         cmd[3] = 0x3;
  302.     else
  303.     if(strcmp(modifier,m4) == 0)
  304.         cmd[3] = 0x4;
  305.     else
  306.     if(strcmp(modifier,m5) == 0)
  307.         cmd[3] = 0x5;
  308.     else
  309.     if(strcmp(modifier,m6) == 0)
  310.         cmd[3] = 0x6;
  311.     else
  312.     if(strcmp(modifier,m7) == 0)
  313.         cmd[3] = 0x7;
  314.     else
  315.     if(strcmp(modifier,m8) == 0)
  316.         cmd[3] = 0x8;
  317.     else
  318.     if(strcmp(modifier,m9) == 0)
  319.         cmd[3] = 0x9;
  320.     else
  321.         {
  322.         errmsg();
  323.         return;
  324.         }
  325.     return;
  326.     }
  327. else
  328. if((strncmp(func,mode,cnt) == 0) && (cnt == 4))
  329.     {
  330.         bytcnt = 8;
  331.         cmd[4] = 0xA;
  332.     if(strcmp(modifier,lsb) == 0)
  333.         cmd[3] = 0x10;
  334.     else
  335.     if(strcmp(modifier,usb) == 0)
  336.         cmd[3] = 0x11;
  337.     else
  338.     if(strcmp(modifier,cw) == 0)
  339.         cmd[3] = 0x12;
  340.     else
  341.     if(strcmp(modifier,am) == 0)
  342.         cmd[3] = 0x13;
  343.     else
  344.     if(strcmp(modifier,fm) == 0)
  345.         cmd[3] = 0x14;
  346.     else
  347.     if(strcmp(modifier,fsk) == 0)
  348.         cmd[3] = 0x15;
  349.     else
  350.         {
  351.         errmsg();
  352.         return;
  353.         }
  354.     return;
  355.     }
  356. else
  357. if((strncmp(func,ham,cnt) == 0) && (cnt == 3))
  358.     {
  359.     bytcnt = 26;
  360.     cmd[4] = 0xA;
  361.     cmd[3] = 0x20;
  362.     return;
  363.     }
  364. else
  365. if((strncmp(func,gen,cnt) == 0) && (cnt == 3))
  366.     {
  367.     bytcnt = 26;
  368.     cmd[4] = 0xA;
  369.     cmd[3] = 0x21;
  370.     return;
  371.     }
  372. else
  373. if((strncmp(func,tone,cnt) == 0) && (cnt == 4))
  374.     {
  375.     bytcnt = 26;
  376.     for(cnt=0;cnt<=15;cnt++)
  377.         func[cnt] = modifier[cnt];
  378.     cnt = parse(func);
  379.     if((strncmp(func,loq,cnt) == 0) && (cnt == 3))
  380.         {
  381.         ptr = &*lstr;
  382.         if(cktone() == FALSE)
  383.             {
  384.             terr();
  385.             return;
  386.             }
  387.         else
  388.             {
  389.             getnumber();
  390.             cmd[4] = 0xC;
  391.             cmd[3] = cmd[1];
  392.             cmd[2] = cmd[0];
  393.             cmd[1] = 0x0;
  394.             }
  395.         }
  396.     else
  397.     if((strncmp(func,hiq,cnt) == 0) && (cnt == 3))
  398.         {
  399.         ptr = &*hstr;
  400.         if(cktone() == FALSE)
  401.             {
  402.             terr();
  403.             return;
  404.             }
  405.         else
  406.             {
  407.             getnumber();
  408.             cmd[4] = 0xC;
  409.             cmd[3] = cmd[1];
  410.             cmd[2] = cmd[0];
  411.             cmd[1] = 0x1;
  412.             }
  413.         }
  414.     else
  415.         {
  416.         errmsg();
  417.         return;
  418.         }
  419.     return;
  420.     }
  421. else
  422. if((strncmp(func,check,cnt) == 0) && (cnt == 5))
  423.     {
  424.     bytcnt = 86;
  425.     cmd[4] = 0x1;
  426.     return;
  427.     }
  428. else
  429. if((strncmp(func,aclr,cnt) == 0) && (cnt == 4))
  430.     {
  431.     bytcnt = 26;
  432.     cmd[4] = 0xA;
  433.     cmd[3] = 0x80;
  434.     return;
  435.     }
  436. else
  437. if((strncmp(func,quit,cnt) == 0) && (cnt == 4))
  438.     {
  439.     bytcnt = 86;
  440.     cmd[4] = 0x0;
  441.     cmd[3] = 0x1;
  442.     endprog = TRUE;
  443.     return;
  444.     }
  445. else
  446. if((strncmp(func,help,cnt) == 0) && (cnt == 4))
  447.     {
  448.     helpscreen();
  449.     getchar();
  450.     bytcnt = 86;
  451.     cmd[4] = 0x1;
  452.     return;
  453.     }
  454. else
  455.     gotoxy(0,22);
  456.     printf("                              ");
  457.     for(cnt = 0;cnt <= 30;cnt++) putchar(8);
  458.     printf("No such command as  [  %s  ]\n",func);
  459.     clear = TRUE;
  460.     return;
  461. }       /*end of match*/
  462.  
  463. void sendcmd()
  464. {
  465. int j,cnt;
  466. char echo[5];
  467.  
  468. cnt = 2;
  469. cmd[5] = 0;
  470. echo[5] = 0;
  471.  
  472. do
  473.     {
  474.     for(j = 0;j <= 4;j++)
  475.         {
  476.         comout(cmd[j]);
  477.         delay();
  478.         }
  479.     for(j=0;j<=4;j++)
  480.         {
  481.         echo[j] = comin();
  482.         delay();
  483.         }
  484.     --cnt;
  485.     }
  486. while((cnt != 0) && (strcmp(cmd,echo) != 0)) ;
  487.  
  488. if((cnt == 0) && (strcmp(cmd,echo) != 0))
  489.     {
  490.     gotoxy(0,22);
  491.     printf("There was a Transmission Error\n");
  492.     clear = TRUE;
  493.     xmiterror = TRUE;
  494.     return;
  495.     }
  496.  
  497. else
  498.     {
  499.     for(j=0;j<=4;j++)            //clear cmd[j] buffer
  500.         cmd[j] = 0;
  501.         cmd[4] = 11;              //load the acknowledgment byte
  502.     for(j=0;j<=4;j++)
  503.         {
  504.         comout(cmd[j]);           //send it
  505.         delay();
  506.         }
  507.     loadstatus();
  508.     }
  509. return;
  510. }       /*end of sendcmd*/
  511.  
  512. errmsg()
  513. {
  514. int cnt;
  515. gotoxy(0,22);
  516. printf("                              ");
  517. for(cnt = 0;cnt <= 30;cnt++) putchar(8);
  518. printf("Proper Modifier Required\n");
  519. clear = TRUE;
  520. }       /*end of error message*/
  521.  
  522. terr()
  523. {
  524. int cnt;
  525. gotoxy(0,22);
  526. printf("                              ");
  527. for(cnt = 0;cnt <= 30;cnt++) putchar(8);
  528. printf("Standard Tone Required\n");
  529. clear = TRUE;
  530. }       /*end of terr message*/
  531.  
  532. getnumber()
  533. {
  534. char *mod,tempbuf[9],*temp;
  535. int i,length;
  536. mod = modifier;
  537. temp = tempbuf;
  538. length = 0;
  539.  
  540. while(*mod != 0)
  541.     {
  542.     if(isdigit(*mod) == 0) *mod++;
  543.     else
  544.         {
  545.         *temp++ = *mod++;
  546.         length++;
  547.         }
  548.     }
  549. *temp = tempbuf[length - 1];
  550. for(i=0;i<=length;i++)
  551.     tempbuf[8 - i] = *temp--;
  552. for(i;i<=8;i++)
  553.     tempbuf[8 - i] = '0';
  554. tempbuf[8] = 0;
  555.  
  556. for(i=0;i<=7;i++)
  557.     {
  558.     tempbuf[i] = tempbuf[i] - 48;   //convert characters to digits
  559.     if(tempbuf[i] < 0)              //do not allow minus digits
  560.     tempbuf[i] = 0x0;
  561.     }
  562.  
  563. cmd[0] = tempbuf[7];
  564.     tempbuf[6] = tempbuf[6] << 4;
  565.     cmd[0] = cmd[0] | tempbuf[6];
  566. cmd[1] = tempbuf[5];
  567.     tempbuf[4] = tempbuf[4] << 4;
  568.     cmd[1] = cmd[1] | tempbuf[4];
  569. cmd[2] = tempbuf[3];
  570.     tempbuf[2] = tempbuf[2] << 4;
  571.     cmd[2] = cmd[2] | tempbuf[2];
  572. cmd[3] = tempbuf[1];
  573.     tempbuf[0] = tempbuf[0] << 4;
  574.     cmd[3] = cmd[3] | tempbuf[0];
  575. }       /*end of getnumber*/
  576.  
  577. loadstatus()
  578. {
  579. int k;
  580. int *stat;
  581. stat = status;
  582. for(k=0;k<=(bytcnt - 1);k++)
  583.     *stat++ = comin();
  584. }       /* end of loadstatus */
  585.  
  586. gotoxy(x,y)
  587. int x,y;
  588. {
  589.     printf("%c[%d;%dH",ESC,y,x);
  590. }       /* end of gotoxy */
  591.  
  592.  
  593. byte1()
  594. {
  595. int k;
  596. k = (bytcnt - 1);
  597.  
  598. if((status[k] & 0x80) != 0)
  599.     {
  600.     gotoxy(8,1);
  601.     printf("CAT Control         ON");
  602.     }
  603. else
  604.     {
  605.     gotoxy(8,1);
  606.     printf("CAT Control        OFF");
  607.     }
  608. if((status[k] & 0x20) != 0)
  609.     {
  610.     gotoxy(40,1);
  611.     printf("Memory channel recall     Active");
  612.     }
  613. else
  614.     {
  615.     gotoxy(40,1);
  616.     printf("Memory channel recall   Inactive");
  617.     }
  618. if((status[k] & 2) != 0)
  619.     {
  620.     gotoxy(8,2);
  621.     printf("Ham/General        Gen");
  622.     }
  623. else
  624.     {
  625.     gotoxy(8,2);
  626.     printf("Ham/General        Ham");
  627.     }
  628. if((status[k] & 4) != 0)
  629.     {
  630.     gotoxy(40,2);
  631.     printf("TX Inhibit                   OFF");
  632.     }
  633. else
  634.     {
  635.     gotoxy(40,2);
  636.     printf("TX Inhibit                    ON");
  637.     }
  638. if((status[k] & 0x10) != 0)
  639.     {
  640.     gotoxy(8,3);
  641.     printf("VFO                  B");
  642.     }
  643. else
  644.     {
  645.     gotoxy(8,3);
  646.     printf("VFO                  A");
  647.     }
  648. if((status[k] & 0x40) != 0)
  649.     {
  650.     gotoxy(40,3);
  651.     printf("Clarifier                     ON");
  652.     }
  653. else
  654.     {
  655.     gotoxy(40,3);
  656.     printf("Clarifier                    OFF");
  657.     }
  658. if((status[k] & 8) != 0)
  659.     {
  660.     gotoxy(8,4);
  661.     printf("Split               ON");
  662.     }
  663. else
  664.     {
  665.     gotoxy(8,4);
  666.     printf("Split              OFF");
  667.     }
  668. if((status[k] & 1) != 0)
  669.     {
  670.     gotoxy(40,4);
  671.     printf("PTT Status              Transmit");
  672.     }
  673. else
  674.     {
  675.     gotoxy(40,4);
  676.     printf("PTT Status               Receive");
  677.     }
  678. }       /* end of byte1 */
  679.  
  680. void cycles(k,x,y)
  681. int k,x,y;
  682. {
  683. char freq[12];
  684. int j,temp[3];
  685.  
  686. temp[3] = status[bytcnt - k--];
  687. temp[2] = status[bytcnt - k--];
  688. temp[1] = status[bytcnt - k--];
  689. temp[0] = status[bytcnt - k];
  690.  
  691. freq[10] = 0;
  692. freq[9] = temp[3];
  693. freq[9] = (freq[9] & 0xf) + 48;
  694. freq[8] = (temp[3] >> 4) + 48;
  695. freq[7] = '.';
  696. freq[6] = temp[2];
  697. freq[6] = (freq[6] & 0xf) + 48;
  698. freq[5] = (temp[2] >>4) + 48;
  699. freq[4] = temp[1];
  700. freq[4] = (freq[4] & 0xf) + 48;
  701. freq[3] = ',';
  702. freq[2] = (temp[1] >> 4) +48;
  703. freq[1] = temp[0];
  704. freq[1] = (freq[1] & 0xf) + 48;
  705. freq[0] = (temp[0] >> 4) + 48;
  706.  
  707. if((freq[0] == '0') && (freq[1] == '0') && (freq[2] == '0'))
  708.     freq[0] = freq[1] = freq[2] = freq[3] = ' ';
  709. if((freq[0] == '0') && (freq[1] == '0'))
  710.     freq[0] = freq[1] = ' ';
  711. if(freq[0] == '0')
  712.     freq[0] = ' ';
  713.  
  714. gotoxy(x,y);
  715. printf("Frequency %s,",freq);
  716. return;
  717. }       /* end of cycles */
  718.  
  719. void mode(m,x,y)
  720. int m,x,y;
  721. {
  722. int temp;
  723. temp = status[bytcnt - m];
  724. switch(temp & 0x7)
  725.     {
  726.     case(0) :
  727.         {
  728.         gotoxy(x,y);
  729.         printf("Mode LSB,");
  730.         break;
  731.         }
  732.     case(1) :
  733.         {
  734.         gotoxy(x,y);
  735.         printf("Mode USB,");
  736.         break;
  737.         }
  738.     case(2) :
  739.         {
  740.         gotoxy(x,y);
  741.         printf("Mode  CW,");
  742.         break;
  743.         }
  744.     case(3) :
  745.         {
  746.         gotoxy(x,y);
  747.         printf("Mode  AM,");
  748.         break;
  749.         }
  750.     case(4) :
  751.         {
  752.         gotoxy(x,y);
  753.         printf("Mode  FM,");
  754.         break;
  755.         }
  756.     case(5) :
  757.         {
  758.         gotoxy(x,y);
  759.         printf("Mode FSK,");
  760.         break;
  761.         }
  762.     default :
  763.         {
  764.         gotoxy(0,22);
  765.         printf("mode Error\n");
  766.         }
  767.     }
  768. return;
  769. }       /* end of mode */
  770.  
  771. void display()
  772. {
  773. int byte,x,y,k;
  774. if(bytcnt == 86)
  775.     CLRSCR;
  776.  
  777. if(bytcnt >= 5)
  778.     {
  779.     byte1();
  780.     drawline(2,5);
  781.     gotoxy(44,6);
  782.     putchar(' ');
  783.     x = 2; y = 6;
  784.     gotoxy(x,y);
  785.     printf("Operating  ");
  786.     byte = 5; x = 13; y = 6;
  787.     cycles(byte,x,y);
  788.     if(bytcnt == 5)
  789.         {
  790.         gotoxy(0,23);
  791.         CLREOL;
  792.         return;
  793.         }
  794.     }
  795.  
  796. if(bytcnt >= 8)
  797.     {
  798.     gotoxy(34,6);
  799.     putchar(' ');
  800.     byte = 7; x = 35; y = 6;
  801.     mode(byte,x,y);
  802.     byte = 8; x = 45; y = 6;
  803.     memchannel(byte,x,y);
  804.     shoband(bytcnt);
  805.     x = 61; y = 6;
  806.     gotoxy(x,y);
  807.     printf(", ");
  808.     byte = 6; x = 63; y = 6;
  809.     ctcsstone(byte,x,y);
  810.     if(bytcnt == 8)
  811.         {
  812.         gotoxy(0,23);
  813.         CLREOL;
  814.         return;
  815.         }
  816.     }
  817.  
  818. if(bytcnt >= 26)
  819.     {
  820.     drawline(2,7);
  821.     x = 11; y = 8;
  822.     gotoxy(x,y);
  823.     printf("VFO A ");
  824.     byte = 18; x = 22; y = 8;
  825.     cycles(byte,x,y);
  826.     byte = 20; x = 44; y = 8;
  827.     mode(byte,x,y);
  828.     byte = 19; x = 54; y = 8;
  829.     ctcsstone(byte,x,y);
  830.     x = 11; y = 9;
  831.     gotoxy(x,y);
  832.     printf("VFO B ");
  833.     byte = 24; x = 22; y = 9;
  834.     cycles(byte,x,y);
  835.     byte = 26; x = 44; y = 9;
  836.     mode(byte,x,y);
  837.     byte = 25; x = 54; y = 9;
  838.     ctcsstone(byte,x,y);
  839.     x = 11; y = 10;
  840.     gotoxy(x,y);
  841.     printf("Clarifier ");
  842.     byte = 12; x = 22; y = 10;
  843.     cycles(byte,x,y);
  844.     byte = 14; x = 44; y = 10;
  845.     mode(byte,x,y);
  846.     byte = 13; x = 54; y = 10;
  847.     ctcsstone(byte,x,y);
  848.     if(bytcnt == 26)
  849.         {
  850.         gotoxy(0,23);
  851.         CLREOL;
  852.         return;
  853.         }
  854.     }
  855.  
  856. if(bytcnt == 86)
  857.     {
  858.     drawline(2,11);
  859. for(k=0;k<=9;k++)
  860.     {
  861.     x = 7; y = (k + 12);
  862.     gotoxy(x,y);
  863.     printf("Memory Channel %d ",k);
  864.     byte = ((k * 6) + 30); x = 25; y = (k + 12);
  865.     cycles(byte,x,y);
  866.     byte = ((k * 6) + 32); x = 47; y = (k + 12);
  867.     mode(byte,x,y);
  868.     byte = ((k * 6) + 31); x = 57; y = (k + 12);
  869.     ctcsstone(byte,x,y);
  870.     {
  871.     gotoxy(0,23);
  872.     CLREOL;
  873.     }
  874.     }
  875.     }
  876. return;
  877. }       /* end of display */
  878.  
  879. memchannel(b,x,y)
  880. int b,x,y;
  881. {
  882. char temp[1];
  883. temp[0] = (status[bytcnt - b] + 48);
  884. temp[1] = 0;
  885. gotoxy(x,y);
  886. printf("Memory Channel %s",temp);
  887. }       /* end of memchannel */
  888.  
  889. ctcsstone(b,x,y)
  890. int b,x,y;
  891. {
  892. int tone;
  893. tone = (status[bytcnt - b] & 0x3f);
  894. gotoxy(x,y);
  895. printf("CTCSS Tone ");
  896. switch(tone)
  897.     {
  898.     case(0) : { puts("  67.0"); break; }
  899.     case(1) : { puts("  71.9"); break; }
  900.     case(2) : { puts("  77.0"); break; }
  901.     case(3) : { puts("  82.5"); break; }
  902.     case(4) : { puts("  88.5"); break; }
  903.     case(5) : { puts("  94.8"); break; }
  904.     case(6) : { puts(" 100.0"); break; }
  905.     case(7) : { puts(" 103.5"); break; }
  906.     case(8) : { puts(" 107.2"); break; }
  907.     case(9) : { puts(" 110.9"); break; }
  908.     case(10) : { puts(" 114.8"); break; }
  909.     case(11) : { puts(" 118.8"); break; }
  910.     case(12) : { puts(" 123.0"); break; }
  911.     case(13) : { puts(" 127.3"); break; }
  912.     case(14) : { puts(" 131.8"); break; }
  913.     case(15) : { puts(" 136.5"); break; }
  914.     case(16) : { puts(" 141.3"); break; }
  915.     case(17) : { puts(" 146.2"); break; }
  916.     case(18) : { puts(" 151.4"); break; }
  917.     case(19) : { puts(" 156.7"); break; }
  918.     case(20) : { puts(" 162.2"); break; }
  919.     case(21) : { puts(" 167.9"); break; }
  920.     case(22) : { puts(" 173.8"); break; }
  921.     case(23) : { puts(" 179.9"); break; }
  922.     case(24) : { puts(" 186.2"); break; }
  923.     case(25) : { puts(" 192.8"); break; }
  924.     case(26) : { puts(" 203.5"); break; }
  925.     case(27) : { puts(" 210.7"); break; }
  926.     case(28) : { puts(" 218.1"); break; }
  927.     case(29) : { puts(" 225.7"); break; }
  928.     case(30) : { puts(" 233.6"); break; }
  929.     case(31) : { puts(" 241.8"); break; }
  930.     case(32) : { puts(" 250.3"); break; }
  931.     case(33) : { puts("C 67.0"); break; }
  932.     case(34) : { puts("C 71.9"); break; }
  933.     case(35) : { puts("C 74.7"); break; }
  934.     case(36) : { puts("C 77.0"); break; }
  935.     case(37) : { puts("C 79.7"); break; }
  936.     case(38) : { puts("C 82.5"); break; }
  937.     case(39) : { puts("C 85.4"); break; }
  938.     case(40) : { puts("C 88.5"); break; }
  939.     case(41) : { puts("C 91.5"); break; }
  940.     default :
  941.         {
  942.         gotoxy(0,22);
  943.         printf("Where did it get that tone?");
  944.         }
  945.     }
  946. }       /* end of ctcsstone */
  947.  
  948. isin(tone)
  949. char *tone;
  950. {
  951. int index;
  952.  
  953. if(strlen(tone) == 0)
  954.     return(FALSE);
  955. else
  956.     {
  957.     index = -1;
  958.         do
  959.             {
  960.             if(! strcmp(tone,ptr[++index]))
  961.             return(1);
  962.             }
  963.         while(strcmp(EDTB,ptr[index]));
  964.             return(0);
  965.     }
  966. }       /* end of isin() */
  967.  
  968. cktone()
  969. {
  970. char buf[8];
  971. int i;
  972. i = 0;
  973. while(modifier[i] != 0)
  974.     {
  975.     buf[i] = modifier[i];
  976.     i++;
  977.     }
  978. buf[i] = 0;
  979. if(isin(&buf) == FALSE) return(FALSE);
  980. else
  981. if(isin(&buf) == TRUE) return(TRUE);
  982. }       /* end of cktone() */
  983.  
  984. drawline(x,y)
  985. int x,y;
  986. {
  987. int i;
  988. gotoxy(x,y);
  989. for(i=0;i<=77;i++)
  990.     putchar(0xC4);
  991. }       /* end of drawline */
  992.  
  993. shoband()
  994. {
  995. int band;
  996. band = status[bytcnt - 7];
  997. band = (band & 120);
  998. band = (band >> 3);
  999. if(status[bytcnt - 2] >= 0x44) band = 15;
  1000. gotoxy(40,22);
  1001. printf("Band = ");
  1002. switch(band)
  1003.     {
  1004.     case(1) : { printf("  1,500.00 MHZ -   2,499.99 MHZ"); break; }
  1005.     case(2) : { printf("  2,500.00 MHZ -   3,999.99 MHZ"); break; }
  1006.     case(3) : { printf("  4,000.00 MHZ -   7,499.99 MHZ"); break; }
  1007.     case(4) : { printf("  7,500.00 MHZ -  10,499.99 MHZ"); break; }
  1008.     case(5) : { printf(" 10,500.00 MHZ -  14,499.99 MHZ"); break; }
  1009.     case(6) : { printf(" 14,500.00 MHZ -  18,499.99 MHZ"); break; }
  1010.     case(7) : { printf(" 18,500.00 MHZ -  21,499.99 MHZ"); break; }
  1011.     case(8) : { printf(" 21,500.00 MHZ -  24,999.99 MHZ"); break; }
  1012.     case(9) : { printf(" 25,000.00 MHZ -  29,999.99 MHZ"); break; }
  1013.     case(10) : { printf(" 50,000.00 MHZ -  59,999.99 MHZ"); break; }
  1014.     case(11) : { printf("144,000.00 MHZ - 149,999.99 MHZ"); break; }
  1015.     case(12) : { printf("430,000.00 MHZ - 439,999.99 MHZ"); break; }
  1016.     case(13) : { printf("    000.00 MHZ -     499.99 MHZ"); break; }
  1017.     case(14) : { printf("    500.00 MHZ -   1,499.99 MHZ"); break; }
  1018.     case(15) : { printf("440,000.00 MHZ - 449,999.99 MHZ"); break; }
  1019.     default : { printf("Frequency outside of Range"); break; }
  1020.     }
  1021. }       /* end of shoband */
  1022.  
  1023. helpscreen()
  1024. {
  1025. CLRSCR;
  1026. printf("COMMAND &  MODIFIERS if ANY        FUNCTION\n");
  1027. printf("check\t\t\t\tGet the status of functions, and redraw screen\n");
  1028. printf("gen\t\t\t\tGeneral coverage receiver\n");
  1029. printf("ham\t\t\t\tAmateur bands only\n");
  1030. printf("quit\t\t\t\tTurn CAT off and terminate program\n");
  1031. printf("up\t\t\t\tTune up 10hz\n");
  1032. printf("dn\t\t\t\tTune down 10hz\n");
  1033. printf("prog\tup/dn & amount\t\tTune Up/Down 00 00 to 99 99 or 0-99.99khz\n");
  1034. printf("band\tup/dn\t\t\tStep Up/Down one ham band or .5 Mhz in Gen\n");
  1035. printf("freq\t(actual)\t\tTune to entered Frequency\n");
  1036. printf("vfo\ta/b/mr\t\t\tVFO/Memory select\n");
  1037. printf("mem\tm(0,1,2,3,4,5,6,7,8,9)\tMemory select\n");
  1038. printf("mode\tlsb/usb/cw/am/fm/fsk\tMode select\n");
  1039. printf("split\t\t\t\tToggle split Frequency operation on/off\n");
  1040. printf("clar\t\t\t\tToggle Clarifier on/off\n");
  1041. printf("mtov\t\t\t\tMemory to VFO\n");
  1042. printf("vtom\t\t\t\tVFO to Memory\n");
  1043. printf("swap\t\t\t\tSwap VFO and Memory\n");
  1044. printf("aclr\t\t\t\tTurn off Split, Clar and Offset\n");
  1045. printf("tone  loq/hiq ctcss frequency\tSet CTCSS TONE\n");
  1046. printf("help\t\t\t\tThis display\n");
  1047. printf("diskmem\t\t\t\tStore or Recall in or from disk Memory\n");
  1048. printf("\t\tPress Enter to return to the control program ---  ");
  1049. }       /*      end of helpscreen       */
  1050.  
  1051. /*initialize com port ( in this case com2)*/
  1052. /*done in assembler for simplicity*/
  1053. initcom()
  1054. {
  1055. __asm
  1056.         {
  1057.         mov     ah,0
  1058.         mov     dx,1            //0 for com1, 1 for com2
  1059.         mov     al,11000111b    //4800 baud, 2 stop bits
  1060.                                         //8 data bits, no parity
  1061.         int     14h
  1062.         }
  1063. }               /*end of initcom*/
  1064.  
  1065. delay()
  1066. {
  1067. int cnt;
  1068.       /*define the value of FACTOR low, even 0 for slow machines*/
  1069.         /*such as 286 @ 8 mhz, 800 works on my 486 @ 66 or @ 33 mhz*/
  1070. for(cnt = 0;cnt <= FACTOR;cnt++) ;
  1071. }               /*end of delay*/
  1072.  
  1073. comin()
  1074. {
  1075. int j;
  1076. unsigned char ch;
  1077. j = TIMEOUT;
  1078. while((_inp(0x2fd) & 0x01) == 0)
  1079. {
  1080.     --j;
  1081.     if(j == 0)
  1082.         break;
  1083. }
  1084. if(j == 0)
  1085. ch = 0;
  1086. else
  1087. ch = (_inp(0x2f8));
  1088. return(ch);
  1089. }       /*end of comin*/
  1090.  
  1091. comout(ch)
  1092. char ch;
  1093. {
  1094. while((_inp(0x2fd) & 0x20) == 0) ;
  1095.      _outp(0x2f8,ch);
  1096. }       /*end of comout*/
  1097.  
  1098. testport()
  1099. {
  1100. int j;
  1101. j = TIMEOUT;
  1102. while( (_inp(0x2fe) & 0x30) == 0)
  1103.         {
  1104.         --j;
  1105.         if(j == 0) return(0xff);
  1106.         }
  1107. return(0);
  1108. }               /*end of testport*/
  1109.  
  1110. startup()
  1111. {
  1112. char func[5],*edit;
  1113. edit = "edit";
  1114. helpscreen();
  1115. gotoxy(0,23);
  1116. CLREOL;
  1117. printf("edit\t    Enter edit now to edit disk memory files or\n");
  1118. printf("\t    Press Enter to proceed to the control program ---  ");
  1119. gets(func);
  1120. if(strlen(func) == 0) ;
  1121. else
  1122. if(strncmp(func,edit,4) == 0)
  1123.     edit_control();
  1124. CLRSCR;
  1125. initcom();
  1126.  
  1127. if(testport() != 0)     
  1128.     {
  1129.     gotoxy(10,10);
  1130.     printf("Check the cable connections and turn on the interface device.\n");
  1131.     gotoxy(0,23);
  1132.     exit(0);
  1133.     }
  1134. bytcnt = 86;
  1135. cmd[3] = 0x0;
  1136. cmd[4] = 0x0;
  1137. sendcmd();
  1138. catflag = TRUE; //the FT-767GX CAT function has been turned on
  1139. display();
  1140. }       /*end of startup*/
  1141.  
  1142. is_ansi()
  1143. {
  1144. FILE *fp,*fopen();
  1145. char ch,buffer[80],*ptr;
  1146. char drive,file[15] = "0:\\config.sys";
  1147. int flag;
  1148.  
  1149. _asm {
  1150.         mov     ax,3305h
  1151.         int     21h
  1152.         mov     drive,dl
  1153.         }
  1154.  
  1155. file[0] = (drive + 64);
  1156. if((fp = fopen(file,"r")) == NULL)
  1157.     {
  1158.     printf("File %s did not open.\n",file);
  1159.     exit(0);
  1160.     } 
  1161.  
  1162. flag = 0;
  1163. ptr = buffer;
  1164. memset(ptr,0,80);
  1165. while((ch = getc(fp)) != EOF)
  1166.     {
  1167.         *ptr++ = tolower(ch);
  1168.         if(ch == '\n')
  1169.             {
  1170.             if((strstr(buffer,"ansi.sys")) != 0)
  1171.                 {
  1172.                 flag = 1;
  1173.                 break;
  1174.                 }
  1175.             else
  1176.                 {
  1177.                 ptr = buffer;
  1178.                 memset(ptr,0,80);
  1179.                 }
  1180.             }
  1181.     }
  1182. fclose(fp);
  1183. if(flag == 0)
  1184. {
  1185. system("cls");
  1186. printf("\n\n\n\n\n\n\n\n");
  1187. printf("\tSome commands from the ANSI.SYS driver are required by this\n");
  1188. printf("\tprogram.  The driver does not appear to be in the boot disk's\n"); 
  1189. printf("\tCONFIG.SYS file.\n\n");  
  1190. printf("\tPlease add a line such as DEVICE=C:\\DOS\\ANSI.SYS to the\n");
  1191. printf("\tCONFIG.SYS file and reboot the system.\n");
  1192. printf("\n\n\n\n\n\n\n");
  1193. exit(0);
  1194. }
  1195. }       /* end of is_ansi */
  1196.  
  1197. main()
  1198. {
  1199. char func[15],*caton,*catoff,*recall,*diskmem;
  1200. int i,k;
  1201. endprog = FALSE;
  1202. catflag = FALSE;
  1203. caton = "cat on";
  1204. catoff = "cat off";
  1205. diskmem = "diskmem";
  1206.  
  1207. is_ansi();
  1208. startup();      
  1209. for(;;)
  1210.     {
  1211.     clear = FALSE;
  1212.     xmiterror = FALSE;
  1213.     for(i=0;i<=15;i++)
  1214.         func[i] = 0;
  1215.     for(i=0;i<=10;i++)
  1216.         cmd[i] = 0;
  1217.     bytcnt = 0;
  1218.     gotoxy(0,23);
  1219.     putchar('>');
  1220.     CLREOL;
  1221.  
  1222.     gets(func);
  1223.     if((strncmp(func,catoff,6) == 0) && (catflag == TRUE)) ;
  1224.     else
  1225.     if((strncmp(func,caton,5) == 0) && (catflag == TRUE)) ; 
  1226.     else 
  1227.     if(strlen(func) == 0) ;
  1228.     else
  1229.     if((strncmp(func,diskmem,7) == 0))
  1230.         {
  1231.         disk_memory_control();
  1232.         do_it("check");
  1233.         display();
  1234.         }
  1235.     else
  1236.         {
  1237.         gotoxy(0,22);
  1238.         printf("                                  \n");
  1239.         match(func,parse(func));
  1240.             if(clear == FALSE)
  1241.                 {
  1242.                 sendcmd();
  1243.                 if(xmiterror == TRUE) ;
  1244.             else
  1245.                 display();
  1246.                 }
  1247.         }
  1248.         if(endprog == TRUE) break;
  1249.     }
  1250. }       /*end of main*/
  1251.  
  1252.  
  1253. void disk_memory_control(void)
  1254. {
  1255. int option;
  1256. do
  1257. {
  1258.     clrscr();
  1259.     printf("\t\t\tAccess to extra memories on disk\n\n");
  1260.     printf("\t\t\t General Coverage Reception and\n");
  1261.     printf("\t\t\t Amateur Band Simplex operation\n\n");
  1262.     printf("\t   1  - Store VFO A  to General Disk Memory\n");
  1263.     printf("\t   2  - Recall General Disk Memory to VFO A\n");
  1264.     printf("\t   3  - View the General Stations file\n");
  1265.     printf("\t   4  - Add Stations to General Coverage disk memory by hand\n");
  1266.     printf("\t   5  - Remove Stations from General Coverage disk memory\n");
  1267.     printf("\n\t\t\t Amateur Band Split Frequency\n");
  1268.     printf("\t\t\t    and Repeater Operation\n\n");
  1269.     printf("\t   6  - Store VFOs to Amateur Band Repeater Disk Memory\n");
  1270.     printf("\t   7  - Recall Amateur Band Repeater Disk Memory to VFOs\n");
  1271.     printf("\t   8  - View the Amateur Band Repeater Stations file\n");
  1272.     printf("\t   9  - Add Stations to Amateur Repeater disk memory by hand\n");
  1273.     printf("\t   10 - Remove Stations from Amateur Repeater disk memory\n");
  1274.     printf("\n\t   11 - To return to main program\n\n");
  1275.     printf("\t        Enter selection  ---   ");
  1276.     scanf("%d",&option);
  1277.     fflush(stdin);
  1278.     }
  1279. while((option < 1) || (option > 11));
  1280. selection(option);
  1281. }       /*end of disk_memory_control*/
  1282.  
  1283. int selection(int choice)
  1284. {
  1285.     switch(choice)
  1286.         {
  1287.         case 1:  store(1); break;
  1288.         case 2:  recall(2); break;
  1289.         case 3:   examine_files(3); break;
  1290.         case 4:  add_station(4); break;
  1291.         case 5:  delete_station(5); break;
  1292.         case 6:  store(6); break;
  1293.         case 7:  recall(7); break;
  1294.         case 8:   examine_files(8); break;
  1295.         case 9:  add_station(9); break;
  1296.         case 10:  delete_station(10); break;
  1297.         default: return(0);
  1298.         }
  1299. }       /*end of selection*/
  1300.  
  1301. void store(int num)
  1302. {
  1303.     int k;
  1304.     clrscr();
  1305.     do_it("check");
  1306.     k = (bytcnt - 1);
  1307.     if((status[k] & 0x10) != 0)
  1308.         {
  1309.         gotoxy(28,10);
  1310.         printf("VFO B is the active VFO");
  1311.         }
  1312.     else
  1313.         {
  1314.         gotoxy(28,10);
  1315.         printf("VFO A is the active VFO");
  1316.         }
  1317.     gotoxy(22,23);
  1318.     printf("Press Enter to contiue, ESC to abort");
  1319.     if(_getch() == ESC) return;
  1320.     if((num == 1) || (num == 6))
  1321.         add_station(num);
  1322. }       /*end of store*/
  1323.  
  1324. void examine_files(int num)
  1325. {
  1326. int record_cnt;
  1327.  
  1328. record_cnt = loadfile(num);
  1329. if(record_cnt != -3)
  1330.     viewfile(record_cnt,num);
  1331. }       /*end of examine_files*/
  1332.  
  1333. int add_station(int num)
  1334. {
  1335. int record_cnt;
  1336.  
  1337. for(;;)
  1338. {
  1339.     record_cnt = loadfile(num);
  1340.     if(record_cnt > -2)
  1341.         {
  1342.         if(num < 6)
  1343.             {
  1344.             if(gen_insert(record_cnt,num) == 1)
  1345.                 viewfile((record_cnt + 1),num);
  1346.             }
  1347.         if(num >= 6)
  1348.             
  1349.             {
  1350.             if(rep_insert(record_cnt,num) == 1)
  1351.                 viewfile((record_cnt + 1),num);
  1352.             }
  1353.         }       
  1354.     else
  1355.         if(record_cnt == -4)
  1356.             {
  1357.             record_cnt = -1;
  1358.             if(num < 6)
  1359.                 {
  1360.                 if(gen_insert(record_cnt,num) == 1)
  1361.                     viewfile((record_cnt + 1),num);
  1362.                 }       
  1363.             if(num >= 6)
  1364.                 {
  1365.                 if(rep_insert(record_cnt,num) == 1)
  1366.                     viewfile((record_cnt + 1),num);
  1367.                 }               
  1368.             }
  1369.         else
  1370.         if(record_cnt == -3) break;
  1371.     clrscr();
  1372. if((num == 1) || (num == 6)) break;
  1373. gotoxy(0,10);
  1374. printf("\n\n\t\tAdd another station? y or n --- ");
  1375. if(getreply() == 1) break;
  1376. }
  1377. }       /*end of add_station*/
  1378.  
  1379. int delete_station(int num)
  1380. {
  1381. int record_cnt,del_rec;
  1382.  
  1383. for(;;)
  1384. {
  1385.     record_cnt = loadfile(num);
  1386.     if(record_cnt == -3) break;
  1387. do
  1388. {
  1389.     viewfile(record_cnt,num);
  1390.     gotoxy(0,24);
  1391.     CLREOL;
  1392.     gotoxy(13,24);
  1393.     printf("Enter the MEM number of the station to be removed --- ");
  1394.     scanf("%d",&del_rec);
  1395. }
  1396. while((del_rec < 1) || (del_rec > (record_cnt + 1)));
  1397.  
  1398. if((del_rec == 1) && (record_cnt == 0))
  1399.     {
  1400.     if(num < 6)
  1401.         system("del general.dat");
  1402.     if(num > 6)
  1403.         system("del repeater.dat");
  1404.     }       
  1405. else
  1406.     {       
  1407.     remove_record(del_rec,record_cnt,num);
  1408.     savedata(record_cnt - 1,num);
  1409.     clrscr();
  1410.     gotoxy(0,10);
  1411.     printf("\n\n\t\tRemove another station? y or n --- ");
  1412.     if(getreply() == 1) break;
  1413.     }
  1414. }
  1415. }       /*end of delete_station*/
  1416.  
  1417. int getreply(void)
  1418. {
  1419. char ch;
  1420. #undef toupper
  1421. do
  1422.     {
  1423.     ch = toupper(_getch());
  1424.     }       while((ch != 'Y') && (ch != 'N'));
  1425.     if(ch == 'Y') return(0);
  1426.     else
  1427.     if(ch == 'N') return(1);
  1428. }       /*end of getreply*/
  1429.  
  1430. void backup(int spaces)
  1431. {
  1432. int i;
  1433. for(i = 0;i <= spaces;++i) BACKSPACE;
  1434. }       /*end of backup*/
  1435.  
  1436. int gen_insert(int rcnt , int num)
  1437. {
  1438. int len,recnum;
  1439. struct general *pt1,*pt2;
  1440. if(num == 4)
  1441.     input_data(4);
  1442. else
  1443.     if(num == 1)
  1444.         get_data(1);
  1445. for(recnum = 0;recnum <= rcnt;++recnum)
  1446.     {
  1447.     if(atol(gentemp.freq) < atol(g[recnum].freq))
  1448.         break;
  1449.     else
  1450.     if(atol(gentemp.freq) == atol(g[recnum].freq))
  1451.         {
  1452.         printf("\n\n\n\n\t\t\tA station is in the list at %s\n",g[recnum].freq);
  1453.         printf("\n\t\t\tPress any key to continue ---  ");
  1454.         _getch();
  1455.         return(0);
  1456.         }
  1457.     else
  1458.     if(atol(gentemp.freq) > atol(g[recnum].freq))
  1459.         ;
  1460.     }
  1461. sprintf(gentemp.rec,"%d",(recnum));
  1462. len = sizeof(struct general);
  1463. if(recnum > rcnt)
  1464.     {
  1465.     pt1 = &gentemp;
  1466.     pt2 = &g[recnum];
  1467.     memcpy(pt2,pt1,len);
  1468.     }
  1469. else
  1470.     {       
  1471.     pt1 = &g[recnum + 1];
  1472.     pt2 = &g[recnum];
  1473.     memmove(pt1,pt2,(rcnt + 1 - recnum) * len);
  1474.     pt1 = &gentemp;
  1475.     pt2 = &g[recnum];
  1476.     memcpy(pt2,pt1,len);
  1477.     }
  1478. reindex(rcnt,num,1);
  1479. savedata(rcnt + 1,num);
  1480. return(1);
  1481. }       /*end of gen_insert*/
  1482.  
  1483. int loadfile(int num)
  1484. {
  1485. FILE *fp,*fopen();
  1486. int i;
  1487. char buff[40],*p1,*p2;
  1488.  
  1489. if(num < 6)
  1490.     {
  1491.     if((fp=fopen("general.dat","r")) == 0)
  1492.         {
  1493.         clrscr();
  1494.         printf("\n\n\n\n\n\n");
  1495.         printf("\t\tFile GENERAL.DAT does not exist.\n");
  1496.         if((num == 2) || (num == 3) || (num == 5))
  1497.             {
  1498.             press_enter(90,24);
  1499.             return(-3);
  1500.             }
  1501.         else
  1502.             {
  1503.             printf("\t\tShould I create a new file? y or n ---  ");
  1504.             i = getreply();
  1505.                 if(i == 1) return(-3);
  1506.                 if(i == 0) return(-4);
  1507.             }
  1508.         }
  1509.     }
  1510.  
  1511. if(num >= 6)
  1512.     {
  1513.     if((fp=fopen("repeater.dat","r")) == 0)
  1514.         {
  1515.         clrscr();
  1516.         printf("\n\n\n\n\n\n");
  1517.         printf("\t\tFile REPEATER.DAT does not exist.\n");
  1518.         if((num == 7) || (num == 8) || (num == 10))
  1519.             {
  1520.             press_enter(90,24);
  1521.             return(-3);
  1522.             }
  1523.         else
  1524.             {
  1525.             printf("\t\tShould I create a new file? y or n ---  ");
  1526.             i = getreply();
  1527.                 if(i == 1) return(-3);
  1528.                 if(i == 0) return(-4);
  1529.             }
  1530.         }
  1531.     }       
  1532. i = 0;
  1533. while(!feof(fp))
  1534. {
  1535.         p1 = buff;
  1536.     if(num < 6)
  1537.         p2 = g[i].rec;
  1538.     if(num >= 6)
  1539.         p2 = r[i].rec;
  1540.         fgets(p1,5,fp);
  1541.     while(*p1 != '\n')
  1542.         *p2++ = *p1++;
  1543.     
  1544.     if(num < 6)
  1545.         {
  1546.         p1 = buff;
  1547.         p2 = g[i].freq;
  1548.         fgets(p1,10,fp);
  1549.     while(*p1 != '\n')
  1550.         *p2++ = *p1++;
  1551.         }
  1552.  
  1553.     if(num >= 6)
  1554.         {
  1555.         p1 = buff;
  1556.         p2 = r[i].afreq;
  1557.         fgets(p1,10,fp);
  1558.     while(*p1 != '\n')
  1559.         *p2++ = *p1++;
  1560.  
  1561.         p1 = buff;
  1562.         p2 = r[i].bfreq;
  1563.         fgets(p1,10,fp);
  1564.     while(*p1 != '\n')
  1565.         *p2++ = *p1++;
  1566.         }
  1567.  
  1568.         p1 = buff;
  1569.     if(num < 6)
  1570.         p2 = g[i].mode;
  1571.     if(num >= 6)
  1572.         p2 = r[i].mode;
  1573.         fgets(p1,5,fp);
  1574.     while(*p1 != '\n')
  1575.         *p2++ = *p1++;
  1576.  
  1577.     if(num < 6) ;
  1578.     if(num >= 6)
  1579.         {
  1580.         p1 = buff;
  1581.         p2 = r[i].tone;
  1582.         fgets(p1,9,fp);
  1583.     while(*p1 != '\n')
  1584.         *p2++ = *p1++;
  1585.         }
  1586.  
  1587.         p1 = buff;
  1588.     if(num < 6)
  1589.         p2 = g[i].call;
  1590.     if(num >= 6)
  1591.         p2 = r[i].call;
  1592.         fgets(p1,10,fp);
  1593.     while(*p1 != '\n')
  1594.         *p2++ = *p1++;
  1595.  
  1596.         p1 = buff;
  1597.     if(num < 6)
  1598.         p2 = g[i].loc;
  1599.     if(num >= 6)
  1600.         p2 = r[i].loc;
  1601.         fgets(p1,36,fp);
  1602.     while(*p1 != '\n')
  1603.         *p2++ = *p1++;
  1604.     ++i;
  1605.     }
  1606. fclose(fp);
  1607. return(i - 2);
  1608. }       /*end of loadfile*/
  1609.  
  1610. int rep_insert(int rcnt , int num)
  1611. {
  1612. int len,recnum;
  1613. struct repeater *pt1,*pt2;
  1614. if(num == 9)
  1615.     input_data(9);
  1616. else
  1617.     if(num == 6)
  1618.         get_data(6);
  1619. for(recnum = 0;recnum <= rcnt;++recnum)
  1620.     {
  1621.     if(atol(reptemp.afreq) < atol(r[recnum].afreq))
  1622.         break;
  1623.     else
  1624.     if(atol(reptemp.afreq) == atol(r[recnum].afreq))
  1625.         {
  1626.         printf("\n\n\n\n\t\t\tA station is in the list at %s\n",r[recnum].afreq);
  1627.         printf("\n\t\t\tPress any key to continue ---  ");
  1628.         _getch();
  1629.         return(0);
  1630.         }
  1631.     else
  1632.     if(atol(reptemp.afreq) > atol(r[recnum].afreq))
  1633.         ;
  1634.     }
  1635. sprintf(reptemp.rec,"%d",(recnum));
  1636. len = sizeof(struct repeater);
  1637. if(recnum > rcnt)
  1638.     {
  1639.     pt1 = &reptemp;
  1640.     pt2 = &r[recnum];
  1641.     memcpy(pt2,pt1,len);
  1642.     }
  1643. else
  1644.     {       
  1645.     pt1 = &r[recnum + 1];
  1646.     pt2 = &r[recnum];
  1647.     memmove(pt1,pt2,(rcnt + 1 - recnum) * len);
  1648.     pt1 = &reptemp;
  1649.     pt2 = &r[recnum];
  1650.     memcpy(pt2,pt1,len);
  1651.     }
  1652. reindex(rcnt,num,1);
  1653. savedata(rcnt + 1,num);
  1654. return(1);
  1655. }       /*end of rep_insert*/
  1656.  
  1657. int savedata(int maxcnt, int num)
  1658. {
  1659. FILE *fp,*fopen();
  1660. int i;
  1661. if(maxcnt < 0)
  1662. return(0);
  1663.  
  1664. if(num < 6)
  1665. {
  1666. if((fp=fopen("general.dat","w")) == 0)
  1667.     {
  1668.     clrscr();
  1669.     printf("\n\n\n\n\n\n\n\t\t\tFile GENERAL.DAT Open Failed\n\n\n");
  1670.     if((fp=fopen("general.dat","r")) != 0)
  1671.         {
  1672.         printf("\t\tWrite protected disk.\n\n");
  1673.         fclose(fp);
  1674.         }
  1675.     return(0);
  1676.     }
  1677. }
  1678.  
  1679. if(num  >= 6)
  1680. {
  1681. if((fp=fopen("repeater.dat","w")) == 0)
  1682.     {
  1683.     clrscr();
  1684.     printf("\n\n\n\n\n\n\n\t\t\tFile REPEATER.DAT Open Failed\n\n\n");
  1685.     if((fp=fopen("repeater.dat","r")) != 0)
  1686.         {
  1687.         printf("\t\tWrite protected disk.\n\n");
  1688.         fclose(fp);
  1689.         }
  1690.     return(0);
  1691.     }
  1692. }
  1693.  
  1694. if(num < 6)
  1695. {
  1696. for(i = 0;i <= maxcnt; ++i)
  1697.     {
  1698.     fprintf(fp,"%s\n",g[i].rec);
  1699.     fprintf(fp,"%s\n",g[i].freq);
  1700.     fprintf(fp,"%s\n",g[i].mode);
  1701.     fprintf(fp,"%s\n",g[i].call);
  1702.     fprintf(fp,"%s\n",g[i].loc);
  1703.     }
  1704. fclose(fp);
  1705. return(0);
  1706. }
  1707.  
  1708. if(num >= 6)
  1709. {
  1710. for(i = 0;i <= maxcnt; ++i)
  1711.     {
  1712.     fprintf(fp,"%s\n",r[i].rec);
  1713.     fprintf(fp,"%s\n",r[i].afreq);
  1714.     fprintf(fp,"%s\n",r[i].bfreq);
  1715.     fprintf(fp,"%s\n",r[i].mode);
  1716.     fprintf(fp,"%s\n",r[i].tone);
  1717.     fprintf(fp,"%s\n",r[i].call);
  1718.     fprintf(fp,"%s\n",r[i].loc);
  1719.     }
  1720. fclose(fp);
  1721. return(0);
  1722. }
  1723. }       /*end of savedata*/
  1724.  
  1725. void input_data(int num)
  1726. {
  1727. char buf[42],*p1,*p2;
  1728. #undef toupper 
  1729. if(num == 4)
  1730.     memset(&gentemp,0,sizeof(struct general) + 1);
  1731. if(num == 9)
  1732.     memset(&reptemp,0,sizeof(struct repeater) + 1);
  1733. clrscr();
  1734. printf("\n\n\n");
  1735. while(TRUE)
  1736.     {
  1737.     if(num == 4)
  1738.     {
  1739.     printf("Enter Station's Frequency             ________");
  1740.     backup(7);
  1741.     gets(gentemp.freq);
  1742.     if(strlen(gentemp.freq) <= 8 && strlen(gentemp.freq) > 0) break;
  1743.     }
  1744.     if(num == 9)
  1745.     {
  1746.     printf("Enter Station's VFO A Frequency       ________");
  1747.     backup(7);
  1748.     gets(reptemp.afreq);
  1749.     if(strlen(reptemp.afreq) <= 8 && strlen(reptemp.afreq) > 0) break;
  1750.     }
  1751.     }
  1752. if(num == 4) ;
  1753. else
  1754. if(num == 9)
  1755. {
  1756. while(TRUE)
  1757.     {
  1758.     printf("Enter Station's VFO B Frequency       ________");
  1759.     backup(7);
  1760.     if(num == 9)
  1761.     gets(reptemp.bfreq);
  1762.     if(strlen(reptemp.bfreq) <= 8 && strlen(reptemp.bfreq) > 0) break;
  1763.     }
  1764. }
  1765.  
  1766. while(TRUE)
  1767.     {
  1768.     printf("Enter Station's Mode                  ___");
  1769.     backup(2);
  1770.     p1 = buf;
  1771.     if(num == 4)
  1772.         p2 = gentemp.mode;
  1773.     if(num == 9)
  1774.         p2 = reptemp.mode;
  1775.     gets(buf);
  1776.     if(strlen(buf) <= 3 && strlen(buf) > 0) break;
  1777.     }
  1778.     while(*p1 != 0)
  1779.         *p2++ = toupper(*p1++);
  1780.         *p2 = 0;
  1781.  
  1782. if(num == 4) ;
  1783. else
  1784. {
  1785. if(num == 9)
  1786.     {
  1787.     while(TRUE)
  1788.         {
  1789.         printf("Enter Station's CTCSS TONE            _______");
  1790.         backup(6);
  1791.         p1 = buf;
  1792.         p2 = reptemp.tone;
  1793.         gets(buf);
  1794.         if(strlen(buf) <= 7 && strlen(buf) > 0) break;
  1795.         }
  1796.     while(*p1 != 0)
  1797.         {
  1798.         if(isalpha(*p1) != 0)
  1799.             *p2++ = toupper(*p1++);
  1800.         else
  1801.             *p2++ = *p1++; 
  1802.         }
  1803.     }
  1804. }
  1805.  
  1806. while(TRUE)
  1807.     {
  1808.     printf("Enter Station's Call Letters          ________");
  1809.     backup(7);
  1810.     p1 = buf;
  1811.     if(num == 4)
  1812.         p2 = gentemp.call;
  1813.     if(num == 9)
  1814.         p2 = reptemp.call;
  1815.     gets(buf);
  1816.     if(strlen(buf) <= 8 && strlen(buf) > 0) break;
  1817.     }
  1818.     while(*p1 != 0)
  1819.         {
  1820.         if(isalpha(*p1) != 0)
  1821.             *p2++ = toupper(*p1++);
  1822.         else
  1823.             *p2++ = *p1++; 
  1824.         }
  1825.  
  1826. while(TRUE)
  1827.     {
  1828. printf("Enter Station's Location       __________________________________");
  1829.     backup(33);
  1830.     p1 = buf;
  1831.     if(num == 4)
  1832.         p2 = gentemp.loc;
  1833.     if(num == 9)
  1834.         p2 = reptemp.loc;
  1835.     gets(buf);
  1836.     if(strlen(buf) <= 34 && strlen(buf) > 0) break;
  1837.     }
  1838.     while(*p1 != 0)
  1839.         *p2++ = toupper(*p1++);
  1840.         *p2 = 0; 
  1841. }       /*end of input_data*/
  1842.  
  1843. void remove_record(int del , int cnt , int num)
  1844. {
  1845. int i,j,len,dest;
  1846. dest = (del - 1);
  1847. if(num < 6)
  1848.     {
  1849.     len = sizeof(struct general);
  1850.     ptg1 = &g[dest];
  1851.     ptg2 = &g[del];
  1852.     memmove(ptg1,ptg2,((cnt + 2) - del)*(len));
  1853.     }
  1854. if(num > 6)
  1855.     {
  1856.     len = sizeof(struct repeater);
  1857.     ptr1 = &r[dest];
  1858.     ptr2 = &r[del];
  1859.     memmove(ptr1,ptr2,((cnt + 2) - del)*(len));
  1860.     }
  1861. reindex(cnt,num,0);
  1862. }       /*end of remove_record*/
  1863.  
  1864. void reindex(int cnt , int num , int j)
  1865. {
  1866. int i;
  1867. for(i = 0;i <= (cnt + j); ++i)
  1868.     {
  1869.     if(num < 6)
  1870.         sprintf(g[i].rec,"%d",(i + 1));
  1871.     if(num >= 6)
  1872.         sprintf(r[i].rec,"%d",(i + 1));
  1873.     }
  1874. }       /*end of reindex*/
  1875.  
  1876. void viewfile(int cnt , int num)
  1877. {
  1878. int i;
  1879. char buff[12],ch;
  1880.  
  1881. clrscr();
  1882. if( num < 6)
  1883.     {
  1884. printf("MEM     Frequency   Mode   Call\t        Location & Comments\n\n");
  1885.     }
  1886. else
  1887.     {
  1888. printf("MEM    Frequency  Mode   CTCSS    Call        Location & Comments\n");
  1889.     }
  1890. for(i = 0;i <= cnt; ++i)
  1891. {
  1892. if(num < 6)
  1893.     {
  1894.     convert(buff,g[i].freq);
  1895.     printf("%-3s   %10s    %-3s    %-8s     %-34s\n",g[i].rec,buff,
  1896.     g[i].mode,g[i].call,g[i].loc);
  1897.     }
  1898. else                             
  1899.     {       
  1900.     convert(buff,r[i].afreq);
  1901.     printf("%-3s A %10s  %-3s   %7s   %-8s %-34s\n",r[i].rec,buff,
  1902.     r[i].mode,r[i].tone,r[i].call,r[i].loc);
  1903.     convert(buff,r[i].bfreq);
  1904.     printf("    B %10s  %-3s   %7s   %-8s %-34s\n",buff,
  1905.     r[i].mode,r[i].tone,r[i].call,r[i].loc);
  1906.     }
  1907. if(num < 6)
  1908.     {
  1909.     if(((i + 1) % 20) == 0 && (i > 0) && (i < cnt))
  1910.         {       
  1911.         if((num == 2) || (num == 5))
  1912.             {
  1913.             gotoxy(14,24);
  1914.         printf("Press ESC to stop paging or any other key for next page --- ");
  1915.             if((ch = _getch()) == ESC)
  1916.                 break;
  1917.             }
  1918.         else
  1919.             press_enter(91,24);
  1920. clrscr();
  1921. printf("MEM     Frequency   Mode   Call\t        Location & Comments\n\n");
  1922.         }
  1923.     }
  1924. else
  1925.     {
  1926.     if(((i + 1) % 10) == 0 && (i > 0) && (i < cnt))
  1927.         {       
  1928.         if((num == 7) || (num == 10))
  1929.             {
  1930.             gotoxy(14,24);
  1931.         printf("Press ESC to stop paging or any other key for next page --- ");
  1932.             if((ch = _getch()) == ESC)
  1933.                 break;
  1934.             }
  1935.         else
  1936.             press_enter(91,24);
  1937. clrscr();
  1938. printf("MEM    Frequency  Mode   CTCSS    Call        Location & Comments\n");
  1939.         }
  1940.     }
  1941. }
  1942. if(ch != ESC)
  1943.     press_enter(90,24);
  1944. }       /*end of viewfile*/
  1945.  
  1946. void press_enter(int x, int y)
  1947. {
  1948. if(x == 90)
  1949.     {
  1950.     gotoxy(0,y);
  1951.     printf("\t\t      End of file     Press ENTER to continue --- ");
  1952.     }
  1953. else
  1954. if(x == 91)
  1955.     {
  1956.     gotoxy(0,y);
  1957.     printf("\t\t     Press ENTER to continue to the next page --- ");
  1958.     }
  1959. else
  1960.     {
  1961.     gotoxy(x,y);
  1962.     printf("Press ENTER to continue --- ");
  1963.     }
  1964. while(_getch() != '\r')
  1965.     gotoxy(61,y);
  1966. }       /*end of press_enter*/
  1967.  
  1968. char *convert(char *buff , char *freq)
  1969. {
  1970. int i,l;
  1971. char first[10];
  1972. char second[12];
  1973.  
  1974.     memset(first,0,10);
  1975.     memset(second,0,12);
  1976.     memcpy(first,freq,strlen(freq));
  1977.     l = strlen(first);
  1978.     second[10] = first[l];
  1979.     second[9] = first[l - 1];
  1980.     second[8] = first[l - 2];
  1981.     second[7] = '.';
  1982.     second[6] = first[l - 3];
  1983.     second[5] = first[l - 4];
  1984.     second[4] = first[l - 5];
  1985.     if(l > 5) 
  1986.     second[3] = ',';
  1987.     else second[3] = ' ';
  1988.     if(l >= 6) 
  1989.     second[2] = first[l - 6];
  1990.     else second[2] = ' ';
  1991.     if(l >= 7) 
  1992.     second[1] = first[l - 7];
  1993.     else second[1] = ' ';
  1994.     if(l >= 8) 
  1995.     second[0] = first[l - 8];
  1996.     else second[0] = ' ';
  1997.     for(i = 0;i <= strlen(second);i++)
  1998.         *(buff + i) = second[i];
  1999.     return(buff);
  2000. }       /*end of convert*/
  2001.  
  2002. void recall(int num)
  2003. {
  2004. int k;
  2005. char fbuf[15],mbuf[8],freq[5] = "freq ",mode[5] = "mode ";
  2006. char *loq,*hiq,*p1,*p2,buff[5];
  2007. char tonebuf[18],loqtone[9] = "tone loq ",hiqtone[9] = "tone hiq ";
  2008.  
  2009. clrscr();
  2010. gotoxy(15,8);
  2011. printf("If you know the MEM number of the station you want");
  2012. gotoxy(34,10);
  2013. printf("Enter it now,");
  2014. gotoxy(19,12);
  2015. printf("or Enter a 0 to view the station list --- ");
  2016. gotoxy(15,14);
  2017. printf("Examine the contents of the Data File and take note\n");
  2018. gotoxy(15,16);
  2019. printf("of the MEM number of the station you wish to recall.");
  2020. gotoxy(25,18);
  2021. printf("Enter it when directed to do so.");
  2022. gotoxy(61,12);
  2023. scanf("%d",&k);
  2024. clrscr();
  2025.  
  2026. if(loadfile(num) == -3)
  2027.     return;
  2028.  
  2029. if(k == 0)
  2030.     {
  2031.     examine_files(num);
  2032.     gotoxy(0,24);
  2033.     CLREOL;
  2034.     gotoxy(23,24);
  2035.     printf("Enter the selected MEM number --- ");
  2036.     scanf("%i",&k);
  2037.     k--;
  2038.     }
  2039. else
  2040.     {
  2041.     loadfile(num);
  2042.     k--;
  2043.     }
  2044.  
  2045. #undef tolower 
  2046. if(num < 6)
  2047.     {
  2048.     do_it("aclr");
  2049.     do_it("gen");
  2050.     do_it("vfo a");
  2051.     
  2052.     memcpy(fbuf,freq,5);
  2053.     memcpy(fbuf + 5,g[k].freq,strlen(g[k].freq) + 1);
  2054.     do_it(fbuf);
  2055.  
  2056.     p1 = g[k].mode;
  2057.     p2 = buff;
  2058.     while(*p1 != 0)
  2059.         *p2++ = tolower(*p1++);
  2060.         *p2 = 0;
  2061.     memcpy(mbuf,mode,5);
  2062.     memcpy(mbuf + 5,buff,strlen(buff) + 1);
  2063.     do_it(mbuf);
  2064.     }
  2065. else
  2066.     {
  2067.     do_it("aclr");
  2068.     do_it("ham");
  2069.  
  2070.     do_it("vfo b");
  2071.     memcpy(fbuf,freq,5);
  2072.     memcpy(fbuf + 5,r[k].bfreq,strlen(r[k].bfreq) + 1);
  2073.     do_it(fbuf);
  2074.  
  2075.     p1 = r[k].mode;
  2076.     p2 = buff;
  2077.     while(*p1 != 0)
  2078.         *p2++ = tolower(*p1++);
  2079.         *p2 = 0;
  2080.     memcpy(mbuf,mode,5);
  2081.     memcpy(mbuf + 5,buff,strlen(buff) + 1);
  2082.     do_it(mbuf);
  2083.  
  2084.     if(r[k].tone[0] == 'C')
  2085.         {
  2086.         hiq = r[k].tone;
  2087.         while(isdigit(*hiq) == 0) hiq++;
  2088.         memcpy(tonebuf,hiqtone,9);
  2089.         memcpy(tonebuf + 9,hiq,strlen(r[k].tone) - 1);
  2090.         do_it(tonebuf);
  2091.         }       
  2092.     else    
  2093.         {
  2094.         loq = r[k].tone;
  2095.         while(isdigit(*loq) == 0) loq++;
  2096.         memcpy(tonebuf,loqtone,9);
  2097.         memcpy(tonebuf + 9,loq,strlen(r[k].tone) + 1);
  2098.         do_it(tonebuf);
  2099.         }       
  2100.     do_it("vfo a");
  2101.     memcpy(fbuf,freq,5);
  2102.     memcpy(fbuf + 5,r[k].afreq,strlen(r[k].afreq) + 1);
  2103.     do_it(fbuf);
  2104.  
  2105.     p1 = r[k].mode;
  2106.     p2 = buff;
  2107.     while(*p1 != 0)
  2108.         *p2++ = tolower(*p1++);
  2109.         *p2 = 0;
  2110.     memcpy(mbuf,mode,5);
  2111.     memcpy(mbuf + 5,buff,strlen(buff) + 1);
  2112.     do_it(mbuf);
  2113.  
  2114.     if(r[k].tone[0] == 'C')
  2115.         {
  2116.         hiq = r[k].tone;
  2117.         while(isdigit(*hiq) == 0) hiq++;
  2118.         memcpy(tonebuf,hiqtone,9);
  2119.         memcpy(tonebuf + 9,hiq,strlen(r[k].tone) - 1);
  2120.         do_it(tonebuf);
  2121.         }
  2122.     else
  2123.         {
  2124.         loq = r[k].tone;
  2125.         while(isdigit(*loq) == 0) loq++;
  2126.         memcpy(tonebuf,loqtone,9);
  2127.         memcpy(tonebuf + 9,loq,strlen(r[k].tone) + 1);
  2128.         do_it(tonebuf);
  2129.         }
  2130.     do_it("split on");
  2131.     }
  2132. }       /*end of recall*/
  2133.  
  2134. void do_it(char *func)
  2135. {
  2136. int cnt;
  2137.     match(func,parse(func));
  2138.     sendcmd();
  2139.     for(cnt = 0;cnt <= 18000;cnt++);
  2140. }       /*end of do_it*/
  2141.  
  2142. char *hertz(char *buffer, int k)
  2143. {
  2144. char freq[12];
  2145. int j,temp[3];
  2146.  
  2147. temp[3] = status[bytcnt - k--];
  2148. temp[2] = status[bytcnt - k--];
  2149. temp[1] = status[bytcnt - k--];
  2150. temp[0] = status[bytcnt - k];
  2151.  
  2152. freq[8] = 0;
  2153. freq[7] = temp[3];
  2154. freq[7] = (freq[7] & 0xf) + 48;
  2155. freq[6] = (temp[3] >> 4) + 48;
  2156. freq[5] = temp[2];
  2157. freq[5] = (freq[5] & 0xf) + 48;
  2158. freq[4] = (temp[2] >>4) + 48;
  2159. freq[3] = temp[1];
  2160. freq[3] = (freq[3] & 0xf) + 48;
  2161. freq[2] = (temp[1] >> 4) +48;
  2162. freq[1] = temp[0];
  2163. freq[1] = (freq[1] & 0xf) + 48;
  2164. freq[0] = (temp[0] >> 4) + 48;
  2165.  
  2166. if((freq[0] == '0') && (freq[1] == '0') && (freq[2] == '0'))
  2167.     freq[0] = freq[1] = freq[2] =  ' ';
  2168. if((freq[0] == '0') && (freq[1] == '0'))
  2169.     freq[0] = freq[1] = ' ';
  2170. if(freq[0] == '0')
  2171.     freq[0] = ' ';
  2172. for(j = 0;j <= strlen(freq);j++)
  2173.     *(buffer + j) = freq[j];
  2174. return(buffer);
  2175. }       /* end of hertz */
  2176.  
  2177. void vfo_mode(int m)
  2178. {
  2179.     int temp;
  2180.     char mbuff[5],*p1,*p2;
  2181.     p1 = mbuff;
  2182.     temp = status[bytcnt - m];
  2183.     switch(temp & 0x7)
  2184.         {
  2185.         case(0) : p1 = "LSB"; break;
  2186.         case(1) : p1 = "USB"; break;
  2187.         case(2) : p1 = "CW"; break;
  2188.         case(3) : p1 = "AM"; break;
  2189.         case(4) : p1 = "FM"; break;
  2190.         case(5) : p1 = "FSK"; break;
  2191.         }
  2192. if(m == 7)
  2193.     p2 = gentemp.mode;
  2194. else
  2195.     if(m == 20)
  2196.         p2 = reptemp.mode;
  2197.     while(*p1 != 0)
  2198.         *p2++ = *p1++;
  2199.         *p2 = 0;
  2200. } /*end of vfo_mode*/
  2201.  
  2202. void get_data(int num)
  2203. {
  2204. char buf[42],*p1,*p2;
  2205. #undef toupper
  2206. if(num == 1)
  2207.     memset(&gentemp,0,sizeof(struct general) + 1);
  2208. if(num == 6)
  2209.     memset(&reptemp,0,sizeof(struct repeater) + 1);
  2210. clrscr();
  2211. printf("\n\n\n");
  2212. if(num == 1)
  2213. {
  2214.     hertz(gentemp.freq,5);
  2215.     vfo_mode(7);
  2216. }
  2217. if(num == 6)
  2218. {
  2219. hertz(reptemp.afreq,18);
  2220. vfo_mode(20);
  2221. hertz(reptemp.bfreq,24);
  2222. pl_tone(25);
  2223. }
  2224. while(TRUE)
  2225.     {
  2226.     printf("Enter Station's Call Letters   ________");
  2227.     backup(7);
  2228.     p1 = buf;
  2229.     if(num == 1)
  2230.         p2 = gentemp.call;
  2231.     if(num == 6)
  2232.         p2 = reptemp.call;
  2233.     gets(buf);
  2234.     if(strlen(buf) <= 8 && strlen(buf) > 0) break;
  2235.     }
  2236.     while(*p1 != 0)
  2237.         {
  2238.         if(isalpha(*p1) != 0)
  2239.             *p2++ = toupper(*p1++);
  2240.         else
  2241.             *p2++ = *p1++; 
  2242.         }
  2243. while(TRUE)
  2244.     {
  2245. printf("Enter Station's Location       __________________________________");
  2246.     backup(33);
  2247.     p1 = buf;
  2248.     if(num == 1)
  2249.         p2 = gentemp.loc;
  2250.     if(num == 6)
  2251.         p2 = reptemp.loc;
  2252.     gets(buf);
  2253.     if(strlen(buf) <= 34 && strlen(buf) > 0) break;
  2254.     }
  2255.     while(*p1 != 0)
  2256.         *p2++ = toupper(*p1++);
  2257.         *p2 = 0; 
  2258. }       /*end of get_data*/
  2259.  
  2260. void pl_tone(int b)
  2261. {
  2262. int tone;
  2263. char tbuf[9],*p1,*p2;
  2264. p1 = tbuf;
  2265. tone = (status[bytcnt - b] & 0x3f);
  2266. switch(tone)
  2267.     {
  2268.     case(0) : p1 = "  67.0"; break;
  2269.     case(1) : p1 = "  71.9"; break;
  2270.     case(2) : p1 = "  77.0"; break;
  2271.     case(3) : p1 = "  82.5"; break;
  2272.     case(4) : p1 = "  88.5"; break;
  2273.     case(5) : p1 = "  94.8"; break;
  2274.     case(6) : p1 = " 100.0"; break;
  2275.     case(7) : p1 = " 103.5"; break;
  2276.     case(8) : p1 = " 107.2"; break;
  2277.     case(9) : p1 = " 110.9"; break;
  2278.     case(10) : p1 = " 114.8"; break;
  2279.     case(11) : p1 = " 118.8"; break;
  2280.     case(12) : p1 = " 123.0"; break;
  2281.     case(13) : p1 = " 127.3"; break;
  2282.     case(14) : p1 = " 131.8"; break;
  2283.     case(15) : p1 = " 136.5"; break;
  2284.     case(16) : p1 = " 141.3"; break;
  2285.     case(17) : p1 = " 146.2"; break;
  2286.     case(18) : p1 = " 151.4"; break;
  2287.     case(19) : p1 = " 156.7"; break;
  2288.     case(20) : p1 = " 162.2"; break;
  2289.     case(21) : p1 = " 167.9"; break;
  2290.     case(22) : p1 = " 173.8"; break;
  2291.     case(23) : p1 = " 179.9"; break;
  2292.     case(24) : p1 = " 186.2"; break;
  2293.     case(25) : p1 = " 192.8"; break;
  2294.     case(26) : p1 = " 203.5"; break;
  2295.     case(27) : p1 = " 210.7"; break;
  2296.     case(28) : p1 = " 218.1"; break;
  2297.     case(29) : p1 = " 225.7"; break;
  2298.     case(30) : p1 = " 233.6"; break;
  2299.     case(31) : p1 = " 241.8"; break;
  2300.     case(32) : p1 = " 250.3"; break;
  2301.     case(33) : p1 = "C 67.0"; break;
  2302.     case(34) : p1 = "C 71.9"; break;
  2303.     case(35) : p1 = "C 74.7"; break;
  2304.     case(36) : p1 = "C 77.0"; break;
  2305.     case(37) : p1 = "C 79.7"; break;
  2306.     case(38) : p1 = "C 82.5"; break;
  2307.     case(39) : p1 = "C 85.4"; break;
  2308.     case(40) : p1 = "C 88.5"; break;
  2309.     case(41) : p1 = "C 91.5"; break;
  2310.     }
  2311. p2 = reptemp.tone;
  2312. while(*p1 != 0)
  2313.     *p2++ = *p1++;
  2314.     *p2 = 0;
  2315. }       /* end of pl_tone */
  2316.  
  2317. void edit_control(void)
  2318. {
  2319. char option;
  2320.  
  2321. clrscr();
  2322. gotoxy(0,3);
  2323. printf("\t           EDIT  operates independently from the FT-767GX  CAT\n");
  2324. printf("\t      function of this program.  The FT-767GX need not be\n"); 
  2325. printf("\t      turned  on during its use.  EDIT allows the  direct\n"); 
  2326. printf("\t      viewing,  insertion,  and/or  deletion  of  station\n"); 
  2327. printf("\t      records  into/from the disk memory files.  However,\n"); 
  2328. printf("\t      It will  only permit one to change a station's call\n"); 
  2329. printf("\t      letters and/or location and comments about it.\n\n");
  2330. printf("\t      When added to the files, stations are automatically\n"); 
  2331. printf("\t      placed   sorted  in  frequency   order.  Therefore,\n"); 
  2332. printf("\t      editing the  frequencies can not be permitted.\n\n");
  2333. printf("\t      To change a station's frequency, mode or CTCSS tone\n"); 
  2334. printf("\t      remove  the station's record from the file and then\n"); 
  2335. printf("\t      add  it  back  into  the file  with  the  corrected\n"); 
  2336. printf("\t      information.\n");
  2337. press_enter(33,24);
  2338.  
  2339.     clrscr();
  2340.     printf("\t\t\t       Edit disk memories\n\n");
  2341.     printf("\t\t\t General Coverage Reception and\n");
  2342.     printf("\t\t\t Amateur Band Simplex operation\n\n");
  2343.     printf("\t   1  - View the General Stations file\n");
  2344.     printf("\t   2  - Edit a General Station Record\n");
  2345.     printf("\t   3  - Add Stations to General Coverage disk memory by hand\n");
  2346.     printf("\t   4  - Remove Stations from General Coverage disk memory\n");
  2347.     printf("\n\t\t\t Amateur Band Split Frequency\n");
  2348.     printf("\t\t\t    and Repeater Operation\n\n");
  2349.     printf("\t   5  - View the Amateur Band Repeater Stations file\n");
  2350.     printf("\t   6  - Edit an Amateur Band Repeater Station Record\n");
  2351.     printf("\t   7  - Add Stations to Amateur Repeater disk memory by hand\n");
  2352.     printf("\t   8  - Remove Stations from Amateur Repeater disk memory\n");
  2353.     printf("\n\t   9  - To go to main program\n\n");
  2354.     printf("\t        Enter selection --- ");
  2355.     do
  2356.         {
  2357.         gotoxy(45,21);
  2358.         option = _getch();
  2359.         } while((option < '1') || (option > '9'));
  2360. fflush(stdin);
  2361. edit_selection(option);
  2362. }       /*end of edit_control*/
  2363.  
  2364. char edit_selection(char opt)
  2365. {
  2366. char ch;
  2367. switch(opt)
  2368.         {
  2369.         case '1': examine_files(3); break;
  2370.         case '2': edit_records(2); break;
  2371.         case '3': add_station(4); break;
  2372.         case '4': delete_station(5); break;
  2373.         case '5': examine_files(8); break;
  2374.         case '6': edit_records(7); break;
  2375.         case '7': add_station(9); break;
  2376.         case '8': delete_station(10); break;
  2377.         default: return(0);
  2378.         }
  2379. do
  2380. {
  2381.     CLRSCR;
  2382.     gotoxy(0,10);
  2383.     printf("\n\t\t\t   1  - Run CAT program\n");
  2384.     printf("\t\t\t   2  - Return to DOS\n");
  2385.     printf("\n\t\t\t\tEnter selection --- ");
  2386.     ch = _getch();
  2387.     if(ch == '2') exit(0);
  2388.     else
  2389.     if(ch == '1') ;
  2390. }
  2391. while((ch > '2') || (ch < '1'));
  2392. }       /*end of edit_selection*/
  2393.  
  2394. void edit_records(int num)
  2395. {
  2396.     int record_cnt,ed_rec;
  2397.  
  2398. for(;;)
  2399. {
  2400.     record_cnt = loadfile(num);
  2401.     if(record_cnt == -3) break;
  2402.  
  2403. do
  2404. {
  2405.     viewfile(record_cnt,num);
  2406.     gotoxy(0,24);
  2407.     CLREOL;
  2408.     gotoxy(13,24);
  2409.     printf("Enter the MEM number of the station record to be edited --- ");
  2410.     scanf("%d",&ed_rec);
  2411.     ed_rec--;
  2412. }
  2413. while((ed_rec < 1) || (ed_rec > record_cnt));
  2414.  
  2415. if((ed_rec == 1) && (record_cnt == 0))
  2416.     {
  2417.     if(num == 2)
  2418.         system("del general.dat");
  2419.     if(num == 7)
  2420.         system("del repeater.dat");
  2421.     }
  2422. else
  2423.     {
  2424.         edit_station_record(ed_rec,num);
  2425.         if(num == 2)
  2426.             savedata(record_cnt,num);
  2427.         if(num == 7)
  2428.             savedata(record_cnt,num);
  2429.     }       
  2430.     clrscr();
  2431.     gotoxy(0,6);
  2432. if(num == 2)
  2433.     printf("The station's call letters are now %s\n",g[ed_rec].call);
  2434. if(num == 7)
  2435.     printf("The station's call letters are now %s\n",r[ed_rec].call);
  2436. if(num == 2)
  2437.     printf("The station's location and/or comment is now %s\n",g[ed_rec].loc);
  2438. if(num == 7)
  2439.     printf("The station's location and/or comment is now %s\n",r[ed_rec].loc);
  2440.  
  2441.     gotoxy(0,12);
  2442.     printf("\n\n\t\tEdit another station record? y or n --- ");
  2443.     if(getreply() == 1) break;
  2444.     }
  2445. }       /*end of edit_records*/
  2446.  
  2447. void edit_station_record(int rec, int num)
  2448. {
  2449. int i;
  2450. char buf[42],*p1,*p2;
  2451. #undef toupper 
  2452. clrscr();
  2453. printf("\n\n\n");
  2454. if(num == 2)
  2455.     printf("The call letters are now %s\n",g[rec].call);
  2456. if(num == 7)
  2457.     printf("The call letters are now %s\n",r[rec].call);
  2458. printf("Do you wish to edit the call letters? y or n --- ");
  2459. if(getreply() == 1) putchar('\n');
  2460. else
  2461.     {
  2462.         putchar('\n');
  2463.         fflush(stdin);
  2464.         while(TRUE)
  2465.         {
  2466.         printf("Enter Station's Call Letters   ________");
  2467.         backup(7);
  2468.         p1 = buf;
  2469.         if(num == 2)
  2470.             p2 = g[rec].call;
  2471.         if(num == 7)
  2472.             p2 = r[rec].call;
  2473.         for(i = 0;i <= 8;i++)
  2474.             *p2++ = 0;
  2475.         if(num == 2)
  2476.             p2 = g[rec].call;
  2477.         if(num == 7)
  2478.             p2 = r[rec].call;
  2479.         gets(buf);
  2480.         if(strlen(buf) <= 8 && strlen(buf) > 0) break;
  2481.         }
  2482.         while(*p1 != 0)
  2483.             {
  2484.             if(isalpha(*p1) != 0)
  2485.                 *p2++ = toupper(*p1++);
  2486.             else
  2487.                 *p2++ = *p1++; 
  2488.             }
  2489.     }
  2490. printf("\n\n\n");
  2491. if(num == 2)
  2492.     printf("The location and/or comment is now %s\n",g[rec].loc);
  2493. if(num == 7)
  2494.     printf("The location and/or comment is now %s\n",r[rec].loc);
  2495. printf("Do you wish to edit the location and/or comment? y or n --- ");
  2496. if(getreply() == 1) putchar('\n');
  2497. else
  2498.     {
  2499.     putchar('\n');
  2500.     fflush(stdin);
  2501.     while(TRUE)
  2502.     {
  2503. printf("Enter Information       __________________________________");
  2504.         backup(33);
  2505.         p1 = buf;
  2506.         if(num == 2)
  2507.             p2 = g[rec].loc;
  2508.         if(num == 7)
  2509.             p2 = r[rec].loc;
  2510.         for(i = 0;i <= 34;i++)
  2511.                 *p2 = 0;
  2512.         if(num == 2)
  2513.             p2 = g[rec].loc;
  2514.         if(num == 7)
  2515.             p2 = r[rec].loc;
  2516.         gets(buf);
  2517.         if(strlen(buf) <= 34 && strlen(buf) > 0) break;
  2518.         }
  2519.         while(*p1 != 0)
  2520.             *p2++ = toupper(*p1++);
  2521.             *p2 = 0;
  2522.     }
  2523. }       /*end of edit_station_record*/
  2524.